package org.example.utils;

import cn.hutool.json.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author 李国树
 * @version 1.0
 * @Desc
 * @date 2023/11/18 9:08
 */
public class AlipayUtils {
    /**
     * 调用支付宝查询接口解析返回值
     * @param body
     * @return
     */
    public static QueryResult parseTradeQuery(String body){
        JSONObject bodyJSONObject =new JSONObject(body);
        String alipayTradeQueryResponse = bodyJSONObject.getStr("alipay_trade_query_response");
        JSONObject alipayTradeQueryResponseJSONObject = new JSONObject(alipayTradeQueryResponse);
        String tradeStatus = alipayTradeQueryResponseJSONObject.getStr("trade_status");
        String tradeNo = alipayTradeQueryResponseJSONObject.getStr("trade_no");
        String totalAmount = alipayTradeQueryResponseJSONObject.getStr("total_amount");
        String sendPayDate = alipayTradeQueryResponseJSONObject.getStr("send_pay_date");
        QueryResult queryResult = new QueryResult(tradeStatus,tradeNo,totalAmount,sendPayDate);
        return queryResult;
    }
}

 
